package com.lh.api.controller.notice;

import com.lh.api.controller.AbstractController;
import com.lh.api.service.NoticeService;
import com.lh.api.vo.NoticeVo;
import com.lh.common.enums.UpperLowerShelfStatus;
import com.lh.common.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gze
 * @ClassName: NoticeAction
 * @Description: notice相关接口
 * @date: 2020-05-15 14:09
 */
@RestController
@RequestMapping("/api/notice")
@Api(value="NoticeAction",tags={"公告接口"})
public class NoticeAction extends AbstractController {

    @Autowired
    private NoticeService noticeService;

    /**
     * 查询所有公告信息
     */
    @ApiOperation(value = "查询所有公告信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "qureyTime", value = "查询时间,形如:2020-03-01 21:00:00,查询第一页时不用传，由后端返回", required = false,dataTypeClass= String.class),
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "页数大小", required = true,dataTypeClass= Integer.class)
    })
    @GetMapping("/getNoticeList")
    public Result<NoticeVo> getNoticeList(String qureyTime, Integer pageNum, Integer pageSize) {
        if(pageNum != null && pageNum == 1){
            qureyTime = DateTimeUtil.getDateTime();
        }
//        else {
//            AssertUtil.assertNotNull(qureyTime, Constant.RESULT.FI1000, "QureyTime is required");
//        }
        Map<String, Object> params = new HashMap<>();
        params.put("status", UpperLowerShelfStatus.UPPERSHELF);
        params.put("qureyTime", qureyTime);
        PageUtils<NoticeVo> noticeVoPageUtils = noticeService.getNoticeList(params, pageNum, pageSize);
        noticeVoPageUtils.setQureyTime(qureyTime);
        return Result.ok(noticeVoPageUtils);
    }
}
